﻿using Dapper;
using Entity;
using IRealize;
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Realize
{
    public class EI : IEI
    {
        public async Task<int> Add(string HumanName, int InterviewAmount, string HumanMajorKindId, string HumanMajorKindName, string HumanMajorId, string HunmaMajorName, string ImageDegree, string NativeLanguageDegree, string ForeignLanguageDegree, string ResponseSpeedDegree, string EQDegree, string IQDegree, string MultiQualityDegree, string Register, string RegisteTime, string ResumeId,string InterviewComment, string sqlserver)
        {
            using (SqlConnection con = new SqlConnection(sqlserver))
            {
                string sql = $@"insert into engage_interview(human_name,interview_amount,human_major_kind_id,
                                human_major_kind_name,human_major_id,human_major_name,image_degree,native_language_degree,
                                foreign_language_degree,response_speed_degree,EQ_degree,IQ_degree,multi_quality_degree,
                                register,resume_id,registe_time,interview_comment) 
                                values 
                                ('{HumanName}','{InterviewAmount}','{HumanMajorKindId}','{HumanMajorKindName}','{HumanMajorId}',
                                '{HunmaMajorName}','{ImageDegree}','{NativeLanguageDegree}','{ForeignLanguageDegree}','{ResponseSpeedDegree}',
                                '{EQDegree}','{IQDegree}','{MultiQualityDegree}','{Register}','{ResumeId}','{RegisteTime}','{InterviewComment}')";

                int result = await con.ExecuteAsync(sql);
                return result;
            }
        }

        public async Task<Engage_Interview> SelectById_EI(string id, string sqlserver)
        {
            Task<Engage_Interview?> task = Task<Engage_Interview>.Run(() =>
            {
                using (SqlConnection sqlConnection = new SqlConnection(sqlserver))
                {
                    string sql = $@"select * from engage_interview where ein_id = '{id}'";
                    return sqlConnection.Query<Engage_Interview>(sql).FirstOrDefault();
                }
            });
            return await task;
        }

        public async Task<List<Engage_Interview>> Select_EI(string sqlserver)
        {
            Task<List<Engage_Interview>> task = Task<List<Engage_Interview>>.Run(async () =>
            {
                using (SqlConnection con = new SqlConnection(sqlserver))
                {
                    string sql = "select * from engage_interview where check_status =0";
                    return con.Query<Engage_Interview>(sql).ToList();
                }

            });
            return await task;
        }
    }
}
